#include "MultipointMutation.h"
#include "EvolutionaryAlgorithm.h"
#include "Configuration.h"
#include "RandomGenerator.h"
#include "Printer.h"

#include <set>

EvolutionaryAlgorithm::population_type MultipointMutation::mutate(EvolutionaryAlgorithm::population_type & actualPopulation)
{
	EvolutionaryAlgorithm::population_type mutatedPopulation;
	for(EvolutionaryAlgorithm::population_type::iterator genIter = actualPopulation.begin();
		genIter != actualPopulation.end();
		++genIter)
	{
		std::set<int> zeros = genIter->getZeros();
		//std::cout<<"mutuje : " << *genIter;
		//Printer::ciout(zeros);
		std::set<int> choosen = _random.nRandom(zeros, Configuration::mutateNo);
		//Printer::ciout(choosen);

		Genotype tmpGen = *genIter;
		for(std::set<int>::iterator vertIter = choosen.begin(); vertIter != choosen.end(); ++vertIter)
		{
			if (tmpGen.isConnectedToAll(*vertIter))
			{
				tmpGen.set(*vertIter);
			}
		}
		tmpGen.recalculateFitnessValue();
		mutatedPopulation.insert(tmpGen);
	}
	//Printer::ciout(mutatedPopulation);
	//std::cout<<"koniec metody"<<std::endl;
	return mutatedPopulation;
}
